/**
 * Created by rockyren on 14-8-27.
 */
/**
 * @class id与像素范围的对应类
 */

define(function(require,exports,module){
  var cfg = require("../config");

  function CanvasAreas() {
    this.AREA_WIDTH = cfg.AREA_WIDTH;
    this.AREA_HEIGHT = cfg.AREA_HEIGHT;
    //X,Y轴上的区域数
    this.X_NUM = cfg.CVS_WIDTH/this.AREA_WIDTH;
    this.Y_NUM = cfg.CVS_HEIGHT/this.AREA_HEIGHT;

  }

  module.exports = CanvasAreas;



  /**
   * @method 由id得范围
   * @param id
   * @returns {Area} 范围
   */
  CanvasAreas.prototype.getArea = function(id) {
    var x = (id%this.X_NUM) * this.AREA_WIDTH;
    var y = Math.floor((id/this.X_NUM)) * this.AREA_HEIGHT;
    return new Area(id,x,y,this.AREA_WIDTH,this.AREA_HEIGHT);
  };


  /**
   * @method 由坐标得id
   * @param x
   * @param y
   * @returns {number} 返回id
   *
   */
  CanvasAreas.prototype.getId = function(x,y) {
    var id_x = Math.floor(x/this.AREA_WIDTH);
    var id_y = Math.floor(y/this.AREA_HEIGHT);
    var id = id_x + id_y * this.X_NUM;
    return id;
  };



  /**
   * @innerClass 区域范围类
   * @constructor
   */
  function Area(id,x,y,width,height) {
    this.id = id;
    this.x	= x;
    this.y = y;
    this.width = width;
    this.height = height;
  }
})